package cn.initcap.algorithm.leetcode;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * @author initcap
 * @date Created in 2018/11/13 PM2:30.
 */
public class IteratorForRemove {

    public static void main(String[] args) {
        List<Integer> integerList = new ArrayList<>(10);
        for (int i = 0; i < 10; i++) {
            integerList.add(i);
        }
        Iterator<Integer> iterator = integerList.iterator();
        while (iterator.hasNext()) {
            Integer integer = iterator.next();
            if (integer % 2 == 0) {
                iterator.remove();
            }
            if (integer == 3) {
                iterator.remove();
            }
        }
        integerList.forEach(e -> System.out.println(e));
    }

}
